﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MS.InformationManagement.DAL.DocumentCenter;
using MS.InformationManagement.Core.Support;
using Office = Microsoft.Office.DocumentManagement.DocumentSets;
using Microsoft.SharePoint;
using MS.InformationManagement.Support.Constants;


namespace MS.InformationManagement.BLL.GlobalCommands
{
    public class LoadCapturedImageRadicadoCommand : IBaseCommand
    {

        #region Fields

        FileEntity _fileContent;
        Office.DocumentSet _currentDocument;

        #endregion

        #region Constructors

        public LoadCapturedImageRadicadoCommand(FileEntity fileContent, Office.DocumentSet currentDocument)
        {
            _fileContent = fileContent;
            _currentDocument = currentDocument;
        }

        #endregion

        #region Implemented Methods

        public void Execute()
        {
            SPFile newFile = _currentDocument.Folder.Files.Add(_fileContent.FileName, _fileContent.FileContent,true);
            newFile.Item[SPBuiltInFieldId.ContentType] = GlobalConstants.CTTN_ARCHIVE;
            newFile.Item[CustomSiteColumns.FIELD_DOCUMENT_IS_MAIN] = true;
            newFile.Item.Update();
        }

        public void Undo()
        {
            SPFile newFile = _currentDocument.Folder.Files.Add(_fileContent.FileName, _fileContent.FileContent);
            newFile.Delete();
            _currentDocument.Folder.Update();
        }
       
        #endregion

    }
}
